<?php

include_once(APPPATH.'models/baseObject_model.php');

class Admin_operation_model extends BaseObject_model {
	var $dbName = 'baby_mcenter';
	var $tableName = 'sys_operations';
	var $primary_key = 'opId';

	var $defaultCols = 'name,operation,workgroup,description';
	var $defaultOrder = array('opId'=>'asc');

	var $columns = array(
		'opId'=>array('label'=>'权限ID' , 'width'=>50 ,  'primary'=>true , 'isfilter'=>false),
		'operation'=>array('label'=>'权限' , 'width'=>125),
		'name'=>array('label'=>'名称', 'width'=>125),
		'workgroup'=>array('label'=>'工作场景' , 'width'=>125),
		'description'=>array('label'=>'操作描述' , 'width'=>500)
	);

	function __construct() {
		parent::__construct();
		$this->load->database($this->dbName);
	}
	
	function findOperationByOp($name){
		$db = $this->load->database($this->dbName, true);
		$db->select('*');
		$db->from('sys_operations');
		$db->where('operation', $name);
		$query = $db->get();
		$result = $query->row_array();
		$query->free_result();
		return $result;
	}
	
	function findRoleOperations($roleId){
		$db = $this->load->database($this->dbName, TRUE);
		$db->select('o.*');
		$db->from('sys_operations o');
		$db->join('sys_role_operation ro', 'ro.opId = o.opId');
		$db->where('ro.roleId',$roleId);
		$query = $db->get();
		$result = $query->result_array();
		$query->free_result();
		return $result;
	}
	
	function findAllOperations(){
		$db = $this->load->database($this->dbName, TRUE);
		$db->select('*');
		$db->from($this->tableName);
		$query = $db->get();
		$result = $query->result_array();
		$query->free_result();
		return $result;
	}
	
	function save($operation){
		$opId = $operation['opId'];
		if($opId){
			return $this->update($opId , $operation);
		}
		return $this->insert($operation);
	}
}
/* End of file admin_operation_model.php */
/* Location: ./application/models/admin/admin_operation_model.php */